package cn.wiscofile.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.wiscofile.pojo.WiscoApprovalOpinion;


/**
 * A data access object (DAO) providing persistence and search support for
 * WiscoApprovalOpinion entities. Transaction control of the save(), update()
 * and delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see cn.wiscofile.pojo.WiscoApprovalOpinion
 * @author MyEclipse Persistence Tools
 */

public class WiscoApprovalOpinionDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory
			.getLog(WiscoApprovalOpinionDAO.class);
	// property constants
	public static final String FLOWINID = "flowinid";
	public static final String CHECKIDEA = "checkidea";
	public static final String CHECKDESC = "checkdesc";
	public static final String STEPNAME = "stepname";
	public static final String CHECKUSER = "checkuser";

	public void save(WiscoApprovalOpinion transientInstance) {
		log.debug("saving WiscoApprovalOpinion instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(WiscoApprovalOpinion persistentInstance) {
		log.debug("deleting WiscoApprovalOpinion instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public WiscoApprovalOpinion findById(java.lang.String id) {
		log.debug("getting WiscoApprovalOpinion instance with id: " + id);
		try {
			WiscoApprovalOpinion instance = (WiscoApprovalOpinion) getSession()
					.get("cn.wisco.pojo.WiscoApprovalOpinion", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(WiscoApprovalOpinion instance) {
		log.debug("finding WiscoApprovalOpinion instance by example");
		try {
			List results = getSession().createCriteria(
					"cn.wisco.pojo.WiscoApprovalOpinion").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding WiscoApprovalOpinion instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from WiscoApprovalOpinion as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByFlowinid(Object flowinid) {
		return findByProperty(FLOWINID, flowinid);
	}

	public List findByCheckidea(Object checkidea) {
		return findByProperty(CHECKIDEA, checkidea);
	}

	public List findByCheckdesc(Object checkdesc) {
		return findByProperty(CHECKDESC, checkdesc);
	}

	public List findByStepname(Object stepname) {
		return findByProperty(STEPNAME, stepname);
	}

	public List findByCheckuser(Object checkuser) {
		return findByProperty(CHECKUSER, checkuser);
	}

	public List findAll() {
		log.debug("finding all WiscoApprovalOpinion instances");
		try {
			String queryString = "from WiscoApprovalOpinion";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public WiscoApprovalOpinion merge(WiscoApprovalOpinion detachedInstance) {
		log.debug("merging WiscoApprovalOpinion instance");
		try {
			WiscoApprovalOpinion result = (WiscoApprovalOpinion) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(WiscoApprovalOpinion instance) {
		log.debug("attaching dirty WiscoApprovalOpinion instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(WiscoApprovalOpinion instance) {
		log.debug("attaching clean WiscoApprovalOpinion instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}